import React from 'react'
import {
  Button,
  Popconfirm,
  Icon,
  message,
  Modal,
  TreeSelect,
  Radio,
  DatePicker,
  Form,
  Row,
  Col,
  Input,
  Select, Table, Tag, Checkbox, Divider
} from 'antd';
import { Link } from 'dva/router';
import { connect } from 'dva';
import Authentication from '../../../components/authentication';
import {
  auditVideo,
  upDownVideo,
  moveToOther,
  changeState,
  deleteInformation,
  weixinMpList,
  weixinPush,
  getConfig,
  batchEditPlate,
  loginUser
} from '../../../services/fetch';
import { deepClone } from '../../../utils/request';
import ShowTitleList from '../Add/ShowTitleList'
import { timingSafeEqual } from 'crypto';
import { fail } from 'assert';
import './Video.scss';
const Option = Select.Option
const RadioGroup = Radio.Group;
const Item = Form.Item
const { SHOW_PARENT } = TreeSelect;
const RangePicker = DatePicker.RangePicker
const CheckboxGroup = Checkbox.Group;
const { confirm } = Modal;
@Form.create()
@connect(({ video }) => ({
  isShowModal: video.isShowModal,
  video
}))

export default class VideoButton extends React.PureComponent {

  constructor(props) {
    super(props);

    this.state = {
      visible: this.props.visible,
      visible2: false,
      visible3: false,
      visible4: false,
      visible5: false,
      visible6: false,
      visibleEditPlate: false,
      value: undefined,
      table_name: '',
      copy: '',
      pushMsg: 1,
      pushDate: '',
      isNewAdd: false,
      RangePicker: ['', ''],
      keywords: '',  //关键词
      information_id:0,
      valueRangePicker: [],
      selectedRowKeys: [],
      selectedRowKeys2: [],
      index: 1,
      data: {},
      state: '',      //上架状况
      status: '',     //审核状态
      cat: '',//类型
      class_id: '',
      mplist: [],
      mp_checkbox: [],
      config_json: {},
      editPlateIds: [],
      isAggregation:false,
      quanxian:[],
      pushMsgTitle:''
    }
  }
  componentDidMount() {
    this.getQuanxian()
    //订阅
    window.PubSub.subscribe('stopNewAdd', this.stopNewAdd)
    // this.getVideoList()
    getConfig().then((res) => {
      if (res.data.code == 200) {
        // console.log(res);
        this.setState({
          config_json: res.data.data.config_json
        })

      }
    })
    this.props.onRef(this)
    const { search } = window.location
        const paramsString = search.substring(1)
        const searchParams = new URLSearchParams(paramsString)
        if(searchParams.get('type')){
            const type = searchParams.get('type')
            console.log(type)
            if(type==='aggregation'){
                this.setState({
                    isAggregation:true
                })
            }
        }
  }
  getQuanxian = async () => {
    const res = await loginUser({
          token: localStorage.getItem('token'),
          site_id:'00000000000000000000000000000000'
      })
      if(res.data.code === 200) {
        this.setState({quanxian:res.data.data.privilege_list})
      }
      
    }
  changeAggregation=()=>{
    this.setState({
      isAggregation:true
    })
  }

  getVideoList = (index = 1) => {
    const { video } = this.props;
    const { videoList } = video
    let { dispatch } = this.props;
    dispatch({
      type: 'video/getVideoList',
      data: {
        index: index,
        page_size: videoList.pagination.pageSize,
      }
    })
  }
  /**
   * 禁止服务新建   发布订阅处理
   */
  stopNewAdd = (id) => {
    //判断是否为服务版面     禁止新建
    // let id = localStorage.getItem('treeSelectedValue')
    let treeData = this.props.video.treeList
    this.setState({
      isNewAdd: false
    })
    if (treeData.length > 0) {
      treeData.map((item) => {
        if (item.children && item.children.length > 0) {
          item.children.map((i) => {
            if (i.plate_id == id) {
              if (i.template_id == 4) {
                this.setState({
                  isNewAdd: true
                })
              }
            }
          })
        } else {
          if (item.plate_id == id) {
            if (item.template_id == 4) {
              this.setState({
                isNewAdd: true
              })
            }
          }
        }
      })
    }
  }
  showModal2 = () => {
    this.setState({
      visible2: true,
    });
  }
  showEditPlate = () => {
    this.setState({
      visibleEditPlate: true,
    });
  }
  showModal6 = () => {
    /**
     * 上下架视频
     */

    let wx_url = this.state.config_json.weixinUrl;
    if (wx_url && this.state.mplist.length == 0) {
      weixinMpList(wx_url).then((res) => {

        if (res.data.code === 200) {
          this.setState({
            mplist: res.data.data
          })
        }

      })
    }

    this.setState({
      visible6: true,
    });
  }


  // checkbox 改变
  checkboxChange = (checkedValues) => {
    this.setState({
      mp_checkbox: checkedValues
    })
  }

  /**
   * 推送微信矩阵
   */
  handleOk6 = (e) => {
    this.setState({
      visible6: false,
    });

    let id = this.props.video.selectedRowKeys
    let data = this.props.video.dataSource

    let _this = this;
    let time = 0;
    let wx_url = this.state.config_json.weixinUrl;


    id.map((item, index) => {
      setTimeout(function () {
        let now_data = data.list[item];
        if (now_data['type'] != 1) {
          message.error('只能推送文章');
        } else {
          let push_data = {
            'attachments': now_data['information_img'],
            'title': now_data['information_title'],
            'summary': now_data['intro'],
            'content': now_data['content'],
            'reporter': now_data['create_user'],
            'mpid': _this.state.mp_checkbox
          }
          let hideConfig = message.loading('推送中...', 0);
          weixinPush(wx_url, push_data).then((res) => {
            setTimeout(hideConfig, 100);
            if (res.data.code === 200) {
              message.success('推送成功');
            } else {
              message.error('推送失败');
            }
          })
        }


      }, time);
      time += 500;

    })

    this.setState({
      visible3: false,
    });;
  }
  handleCancel6 = () => {
    this.setState({
      visible6: false,
    });
  }
  /**
   * 移动到
   */
  handleOk = (e) => {
    this.setState({
      visible2: false,
    });
    let moreId = this.props.video.selectedRowKeys
    let dataSource = JSON.parse(JSON.stringify(this.props.video.dataSource))
    let moreArr = []
    moreId.map((item, index) => {
      moreArr[index] = dataSource.list[item].plate_information_id
    })
    if (this.state.value) {
      let data = {
        plate_information_ids: moreArr,
        plate_id: this.state.value
      }
      moveToOther(data).then((res) => {
        if (res.data.code === 200) {
          this.props.dispatch({
            type: 'video/getTableList', payload: {
              dataAugment: this.props.video.dataAugment
            }
          })
          this.props.dispatch({ type: 'video/updateMoreDeal', data: [] });
          message.success(res.data.msg)
        } else {
          message.error(res.data.msg)
        }
      })
    }
  }


  handleCancel = (e) => {
    this.setState({
      visible2: false,
    });
  }

  //批量修改版面

  handleChangePlate = (value) => {
    this.setState({
      editPlateIds: value
    });
  }
  handleEditPlateOk = (e) => {

    let moreId = this.props.video.selectedRowKeys
    let dataSource = JSON.parse(JSON.stringify(this.props.video.dataSource))
    let moreArr = moreId.map((item) =>
      dataSource.list[item].plate_information_id
    )
    if (this.state.editPlateIds.length > 0) {
      let data = {
        plate_information_ids: moreArr,
        plate_id: this.state.editPlateIds
      }
      batchEditPlate(data).then((res) => {
        if (res.data.code === 200) {
          this.props.dispatch({
            type: 'video/getTableList', payload: {
              dataAugment: this.props.video.dataAugment
            }
          })
          this.props.dispatch({ type: 'video/updateMoreDeal', data: [] });
          message.success(res.data.msg)
        } else {
          message.error(res.data.msg)
        }
      })
    }
    this.setState({
      visibleEditPlate: false,
      editPlateIds: [],
    });
  }


  handleEditPlateCancel = (e) => {
    this.setState({
      visibleEditPlate: false,
    });
  }
  /**
   * 批量 删除 视频列表数据
   */
  deleteAll = () => {
    var _that = this;
    confirm({
      title: '确认删除所选资讯吗',
      onOk() {
        let moreId = _that.props.video.selectedRowKeys
        let dataSource = JSON.parse(JSON.stringify(_that.props.video.dataSource))
        let moreArr = []
        let isDelete = []
        let matrix_ids = []
        moreId.map((item, index) => {
          moreArr[index] = dataSource.list[item].information_id
          isDelete[index] = dataSource.list[item].state
          matrix_ids[index] = dataSource.list[item].matrix_id
        })
        isDelete = isDelete.filter((i, idx) => (!matrix_ids[idx]))
        let allMatrix = matrix_ids.every( i => !!i)
        // 全是矩阵号或者非矩阵号为下线状态可删除
        if (allMatrix || isDelete.indexOf(1) === -1) {
          let data = {
            information_ids: moreArr,
            table_name: _that.props.video.initTableName
          }
          // for (let i = dataSource.list.length - 1; i >= 0; i--) {
          //     moreArr.map((item, ins) => {
          //         let id = dataSource.list[i].information_id
          //         if ( id === item) {
          //             dataSource.list.splice(i, 1)
          //         }
          //     })
          // }
          // dataSource.total = dataSource.total - moreArr.length
          _that.props.dispatch({
            type: 'video/deleteTableList', payload: {
              dataAugment: data,
              dataSource: _that.props.video.dataAugment
            }
          });
          _that.props.dispatch({ type: 'video/updateMoreDeal', data: [] });
        } else {
          message.error('不可删除已上架资讯')
        }
      }
    })


  }

  /**
   * 审核 状态处理 审核通过
   * 审核: 0:编辑状态 1:待审状态 2:终审通过 3:退回待编
   */
  //审核通过
  auditVideoFun = () => {
    let moreId = this.props.video.selectedRowKeys
    let dataSource = JSON.parse(JSON.stringify(this.props.video.dataSource))
    let moreArr = []
    let matrix_ids = []
    moreId.map((item, index) => {
      moreArr[index] = dataSource.list[item].information_id
      matrix_ids[index] = dataSource.list[item].matrix_id
    })
    let haveMatrix = matrix_ids.some( i => !!i)
    if(haveMatrix) return message.error('选择项包含矩阵号内容，不可审核操作')
    let data = {
      information_ids: moreArr,
      status: 2,
      table_name: this.props.video.initTableName
    }
    this.auditVideoHandle(data, 2)
  }
  //审核拒绝
  auditVideoBack = () => {
    let moreId = this.props.video.selectedRowKeys
    let dataSource = JSON.parse(JSON.stringify(this.props.video.dataSource))
    let moreArr = []
    let matrix_ids = []
    moreId.map((item, index) => {
      moreArr[index] = dataSource.list[item].information_id
      matrix_ids[index] = dataSource.list[item].matrix_id
    })
    let haveMatrix = matrix_ids.some( i => !!i)
    if(haveMatrix) return message.error('选择项包含矩阵号内容，不可审核操作')
    let data = {
      information_ids: moreArr,
      status: 3,
      table_name: this.props.video.initTableName
    }
    this.auditVideoHandle(data, 3)
  }
  //提交审核
  submitAduit = () => {
    let moreId = this.props.video.selectedRowKeys
    let dataSource = JSON.parse(JSON.stringify(this.props.video.dataSource))
    let moreArr = []
    let matrix_ids = []
    moreId.map((item, index) => {
      moreArr[index] = dataSource.list[item].information_id
      matrix_ids[index] = dataSource.list[item].matrix_id
    })
    let haveMatrix = matrix_ids.some( i => !!i)
    if(haveMatrix) return message.error('选择项包含矩阵号内容，不可提交审核')
    let data = {
      information_ids: moreArr,
      status: 1,
      table_name: this.props.video.initTableName
    }
    this.auditVideoHandle(data, 1)
  }
  //审核处理请求封装
  auditVideoHandle = (data, num) => {
    auditVideo(data).then((res) => {
      if (res.data.code === 200) {
        let list = JSON.parse(JSON.stringify(this.props.video.dataSource))
        list.list.map((item, index) => {
          data.information_ids.map((i, ins) => {
            if (item.information_id === i) {
              item.status = num
            }
          })
        })
        this.props.dispatch({ type: 'video/updateTableList', data: list });
        this.props.dispatch({ type: 'video/updateMoreDeal', data: [] });
        message.success(res.data.msg);
      } else {
        message.error(res.data.msg);
      }
    })
  }
  /**
 * 上架  下架
 * record 返回当前 数据
 */
  upVideo = () => {
    let moreId = this.props.video.selectedRowKeys
    let dataSource = JSON.parse(JSON.stringify(this.props.video.dataSource))
    let moreArr = []
    let matrix_ids = []
    moreId.map((item, index) => {
      moreArr[index] = dataSource.list[item].information_id
      matrix_ids[index] = dataSource.list[item].matrix_id
    })
    let haveMatrix = matrix_ids.some( i => !!i)
    if(haveMatrix) return message.error('选择项包含矩阵号内容，不可操作上下架')
    let data = {
      information_ids: moreArr,
      state: 1,
      table_name: this.props.video.initTableName
    }
    setTimeout(() => {

    }, 3000)
    this.upDownVideoFetch(data, 1)
  }
  upVideos = () => {
    let moreId = this.props.video.selectedRowKeys
    let dataSource = JSON.parse(JSON.stringify(this.props.video.dataSource))
    let moreArr = []
    let matrix_ids = []
    moreId.map((item, index) => {
      moreArr[index] = dataSource.list[item].information_id
      matrix_ids[index] = dataSource.list[item].matrix_id
    })
    let haveMatrix = matrix_ids.some( i => !!i)
    if(haveMatrix) return message.error('选择项包含矩阵号内容，不可操作上下架')
    let data = {
      information_ids: moreArr,
      state: 0,
      table_name: this.props.video.initTableName
    }
    setTimeout(() => {

    }, 3000)
    this.upDownVideoFetch(data, 0)
  }
  //封装 上下架 请求
  upDownVideoFetch = (data, num) => {
    upDownVideo(data).then((res) => {
      if (res.data.code === 200) {
        let list = JSON.parse(JSON.stringify(this.props.video.dataSource))
        list.list.map((item, index) => {
          data.information_ids.map((i, ins) => {
            if (item.information_id === i) {
              item.state = num
            }
          })
        })
        this.props.dispatch({ type: 'video/updateTableList', data: list });
        this.props.dispatch({ type: 'video/updateMoreDeal', data: [] });
      }
      message.success(res.data.msg);
    })
  }
  showModal = () => {
    const { dispatch } = this.props;
    // window.PubSub.publish('addModal'); //发布订阅
    // dispatch({
    //     type:'video/showModal'
    // })
    let url;
    if (window.location.origin.indexOf('localhost') > -1) {
      url = window.location.origin + window.location.search + '#/Add';
    } else {
      url = window.location.origin + '/application/fcinformation/web/' + window.location.search + '#/Add';
    }

    window.open(url);
    // dispatch({
    //     type: 'add/addView'
    // })
  }
  /**
   * 移动
   */
  moveSelect = (value, label, extra) => {
    let table_name = extra.triggerNode.props.table_name
    this.setState({
      key: value,
      value: extra.triggerNode.props.plate_id,
      table_name: table_name
    })
  }
  showModalm = () => {
    const { dispatch } = this.props;
    // window.PubSub.publish('addModal'); //发布订阅
    // dispatch({
    //     type:'video/showModal'
    // })
    let url;
    if (window.location.origin.indexOf('localhost') > -1) {
      url = window.location.origin + window.location.search + '#/Addmongolian';
    } else {
      url = window.location.origin + '/application/fcinformation/web/' + window.location.search + '#/Addmongolian';
    }

    window.open(url);
    // dispatch({
    //     type: 'add/addView'
    // })
  }
  /**
   * 编辑
   */

  edit = () => {
    let list = this.props.video.selectedPlateDatas;
    let flag = true;

    list.every(item => {
      if (item.status != 0 && item.status != 3) {
        flag = false;
        return false;
      }
    });
    if (flag) {
      let ids = this.props.video.selectedPlateIds;
      ids = ids.join(',');
      let url;
      if (window.location.origin.indexOf('localhost') > -1) {
        url = window.location.origin + window.location.search + '#/Add/' + ids + '/edit';
      } else {
        url = window.location.origin + '/application/fcinformation/web/' + window.location.search + '#/Add/' + ids + '/edit';
      }

      window.open(url);
    } else {
      message.error('稿件状态只能是草稿或退回');
      return true;
    }
  }
  editm = () => {
    let list = this.props.video.selectedPlateDatas;
    let flag = true;

    list.every(item => {
      if (item.status != 0 && item.status != 3) {
        flag = false;
        return false;
      }
    });
    if (flag) {
      let ids = this.props.video.selectedPlateIds;
      ids = ids.join(',');
      let url;
      if (window.location.origin.indexOf('localhost') > -1) {
        url = window.location.origin + window.location.search + '#/Addmongolian/' + ids + '/editm';
      } else {
        url = window.location.origin + '/application/fcinformation/web/' + window.location.search + '#/Addmongolian/' + ids + '/editm';
      }

      window.open(url);
    } else {
      message.error('稿件状态只能是草稿或退回');
      return true;
    }
  }
  /**
   * 批量复制
   */
  showModal3 = () => {
    this.setState({
      visible3: true,
    });
  }
  handleOk3 = () => {
    let id = this.props.video.selectedRowKeys
    let data = this.props.video.dataSource
    let arr = [];
    let _this = this;
    let time = 0;
    id.map((item, index) => {
      data.list[item].plate_id = this.state.copy
      arr.push(data.list[item]);
      setTimeout(function () {
        _this.props.dispatch({ type: 'video/copy', data: data.list[item] })
      }, time);
      time += 500;

    })
    this.props.dispatch({ type: 'video/updateMoreDeal', data: [] });
    this.setState({
      visible3: false,
    });

    let plate_id = this.state.copy;
    //跳到选中的版面
    this.props.dispatch({
      type: 'video/updatePutTableName', payload: {
        initTableName: plate_id,
        selectedKeys: ["" + plate_id + ""]
      }
    });
    localStorage.setItem('treeSelectedKeys', ["" + plate_id + ""]);
    localStorage.setItem('treeSelectedValue', plate_id);

    //更新当前页码
    this.props.dispatch({ type: 'video/updateIndex', data: 1 });

  }
  handleCancel3 = () => {
    this.setState({
      visible3: false,
    });
  }

  /**
   * 推送消息
   */
  showModal4 = (keyArr) => {
    this.setState({
      visible4: true,
      pushMsgTitle:this.props.video.dataSource.list[keyArr[0]].title
    });
  }
  handleOk4 = () => {
    let idArr = this.props.video.selectedRowKeys
    let dataSource = this.props.video.dataSource
    let dataArr = []
    let nowTime = Date()
    idArr.map((item) => {
      let obj = {
        type: 1,
        push_time: this.state.pushDate,
        intro: dataSource.list[item].intro,
        title:idArr.length==1?this.state.pushMsgTitle:dataSource.list[item].title,
        id: dataSource.list[item].information_id
      }
      dataArr.push(obj)
    })
    let data = {
      push_list: dataArr
    }
    this.props.dispatch({ type: 'video/fcinfoPush', data: data })

    this.setState({
      visible4: false,
    });
  }
  handleCancel4 = () => {
    this.setState({
      visible4: false,
      pushMsgTitle:''
    });
  }

  /**
   * 全局搜索
   */
  showModal5 = () => {
    this.setState({
      visible5: true,
    });
    this.getVideoList()
  }
  handleCancel5 = () => {
    this.setState({
      visible5: false,
    });
  }
  handleOk5 = () => {
    let idArr = this.props.video.selectedRowKeys
    let dataSource = this.props.video.dataSource
    let dataArr = []
    let nowTime = Date()
    idArr.map((item) => {
      let obj = {
        type: 1,
        push_time: this.state.pushDate,
        intro: dataSource.list[item].intro,
        title: dataSource.list[item].title,
        id: dataSource.list[item].information_id
      }
      dataArr.push(obj)
    })
    let data = {
      push_list: dataArr
    }
    this.props.dispatch({ type: 'video/fcinfoPush', data: data })

    this.setState({
      visible4: false,
    });
  }
  //获取日期范围
  getRangePicker = (date, dateString) => {
    this.setState({
      RangePicker: dateString,
      valueRangePicker: date
    })
    console.log(this.state.RangePicker)
  }

  /**
   * 选中事件
   */
  onSelectChange = selectedRowKeys2 => {
    console.log('selectedRowKeys changed: ', selectedRowKeys2);
    this.setState({ selectedRowKeys2 })

  };

  /**
   * 搜索
   */
  searchTable = (index = 1) => {

    let { cat } = this.state;
    let types = [], module_name = '';
    if (cat != '') {

      if (cat.indexOf('a_1') > -1) {  //文章
        types.push(1);
      }
      if (cat.indexOf('a_2') > -1) { //图集
        types.push(2);
      }
      if (cat.indexOf('a_3') > -1) { //banner
        types.push(3);
      }

      if (cat.indexOf('q_theme') > -1) {  //专题
        types = [0];
        module_name = 'fcinformation_theme';
      } else if (cat.indexOf('q_video') > -1) { //视频
        types = [0];
        module_name = 'fcvideo';
      }

      if (cat.indexOf("all") > -1) { //全部
        module_name = '';
        types = '';
      }

      if (cat.indexOf("a_all") > -1) { //所有原文
        types = [1, 2, 3];
      }

      if (cat.indexOf("q_all") > -1) {  //所有引用
        types = [0];
      }
    }


    let data = {
      index: index,
      status: this.state.status,
      types: types,
      module_name: module_name,
      page_size: 10,
      state: this.state.state,
      class_id: this.state.class_id,
      key: this.state.keywords,
      information_id: this.state.information_id,
      start: this.state.RangePicker[0] !== '' ? this.state.RangePicker[0] + " 00:00:00" : '',
      end: this.state.RangePicker[0] !== '' ? this.state.RangePicker[1] + " 23:59:59" : ''
    }
    this.props.dispatch({ type: 'video/getVideoList', data: data });
  }
  /**
   * 重置 搜索
   */
  resetSearch = () => {
    this.setState({
      RangePicker: ['', ''],
      valueRangePicker: [],
      status: '',
      keywords: '',
      information_id:0,
      start: '',
      end: '',
      class_id: '',
      cat: '',
      types: '',
      state: ''
    }, () => {
      this.searchTable()
    })
  }
  handleChange = (value) => {
    this.setState({
      state: value
    })
  }
  handleChange2 = (value) => {
    this.setState({
      status: value
    })
  }
  // pageChange= (page) => { //分页
  //   this.props.dispatch({
  //     type: 'video/getVideoList',
  //     payload: {
  //       ...page
  //     }
  //   })
  // }
  /**
   * 全局 上架  下架
   * record 返回当前 数据
   */
  upVideo2 = () => {
    let moreId = this.state.selectedRowKeys2
    let dataSource = JSON.parse(JSON.stringify(this.props.video.videoList))
    let moreArr = []
    moreId.map((item, index) => {
      moreArr[index] = dataSource.list[item].information_id
    })
    let data = {
      information_ids: moreArr,
      state: 1,
    }
    setTimeout(() => {

    }, 3000)
    this.upDownVideoFetch2(data, 1)
  }
  upVideos2 = () => {
    let moreId = this.state.selectedRowKeys2
    let dataSource = JSON.parse(JSON.stringify(this.props.video.videoList))
    let moreArr = []
    moreId.map((item, index) => {
      moreArr[index] = dataSource.list[item].information_id
    })
    let data = {
      information_ids: moreArr,
      state: 0,
    }
    setTimeout(() => {

    }, 3000)
    this.upDownVideoFetch2(data, 0)
  }
  //全局封装，上下架，请求
  upDownVideoFetch2 = (data, num) => {
    changeState(data).then((res) => {
      if (res.data.code === 200) {
        let list = JSON.parse(JSON.stringify(this.props.video.videoList))
        list.list.map((item, index) => {
          data.information_ids.map((i, ins) => {
            if (item.information_id === i) {
              item.state = num
            }
          })
        })
        this.searchTable(this.props.video.videoList.pagination.page);
        this.resetSelect();
      }
      message.success(res.data.msg);
    })
  }
  /**
   * 批量删除资讯
   */
  deleteAll2 = () => {

    let moreId = this.state.selectedRowKeys2
    let dataSource = JSON.parse(JSON.stringify(this.props.video.videoList))
    let moreArr = []
    let isDelete = []
    moreId.map((item, index) => {
      moreArr[index] = dataSource.list[item].information_id
      isDelete[index] = dataSource.list[item].state
    })
    if (isDelete.indexOf(1) === -1) {
      let data = {
        information_ids: moreArr,
      }
      deleteInformation(data).then((res) => {
        if (res.data.code === 200) {
          this.searchTable(this.props.video.videoList.pagination.page);
          this.resetSelect();
        } else {
          message.error(res.data.msg)
        }
      })
    } else {
      message.error('不可删除已上架资讯')
    }

  }

  /**
   * 重置selectedRowKeys
   */
  resetSelect = () => {
    this.setState({
      selectedRowKeys2: []
    })
  }

  /**
   * 版面跳转
   */
  clickToPlate = (record) => {
    let data = {
      index: 1,
      information_ids: [record.information_id],
      plate_id: record.plate_id
      // key: record.title
    }
    this.setState({
      visible5: false
    })
    //用标题查询列表
    this.props.dispatch({
      type: 'video/getTableList', payload: {
        dataAugment: data
      }
    })
    //设置节点选中
    this.props.dispatch({
      type: 'video/updatePutTableName', payload: {
        initTableName: record.plate_id,
        selectedKeys: [record.plate_id.toString()]
      }
    });
    //展开节点
    this.props.dispatch({ type: 'video/expandedKeys', data: [record.plate_id.toString()] });
  }


  // 展示 蒙文 标题
  showMWList = () => {
    Modal.info({
        className: 'video_MW_List_wrap',
        content: (
          <ul className="video_MW_List">
            {
                this.props.videoData.map(item => {
                    return <li key={item.id}>{item.title}</li>
                })
            }
          </ul>
        ),
        okText: '关闭',
        onOk() {},
    })
}
  render() {
    const { getFieldDecorator } = this.props.form;
    const { selectedRowKeys, treeList, quanxian } = this.props.video;
    // console.log(this.props.video.loginModal, '408');
    const { loginModal } = this.props.video;
    //新建资讯
    const addinformation = () =>
      <Button
        type="defualt"
        onClick={this.showModal}
        disabled={this.state.isNewAdd}
      >
        <Icon type="plus" theme="outlined" />ᠰᠢᠨ᠎ᠡ ᠮᠡᠳᠡᠭᠡᠯᠡᠯ ᠨᠡᠮᠡᠬᠦ
      </Button>
    let addmongolianinfo;
    if (this.state.config_json && this.state.config_json.is_mengwen) {
       addmongolianinfo = () =>
          <Button
              type="defualt"
              onClick={this.showModalm}
              disabled={this.state.isNewAdd}
          >
            <Icon type="plus" theme="outlined"/>新建蒙文资讯
          </Button>
    }
    //全局搜索
    const globalSearch = () =>
      <Button
        type="defualt"
        onClick={this.showModal5}
      >
        <Icon type="search" theme="outlined" />ᠬᠠᠢᠬᠤ
                    </Button>


    //删除
    const deleteinformation = () =>
        <Button type="defualt" disabled={selectedRowKeys.length > 0 ? false : true} onClick={this.deleteAll}>
          <Icon type="delete" theme="outlined" />
          ᠬᠠᠰᠤᠬᠤ
          </Button>

    //引用
    const usedmodule = () =>
      <ShowTitleList id={this.props.video.initTableName} />

    //移动
    const moveinformation = () =>
      <Button type="defualt" disabled={selectedRowKeys.length > 0 ? false : true} onClick={this.showModal2}>
        <Icon type="scissor" theme="outlined" />ᠱᠢᠯᠵᠢᠬᠦᠯᠬᠥ
                </Button>
    //批量修改版面
    const editplate = () =>
      <Button type="defualt" disabled={selectedRowKeys.length > 0 ? false : true} onClick={this.showEditPlate}>
        ᠨᠢᠭᠤᠷ ᠢ᠋ ᠵᠠᠰᠠᠬᠤ
              </Button>

    //提交审核
    const changestatus1 = () =>
      <Button type="defualt" disabled={selectedRowKeys.length > 0 ? false : true} onClick={this.submitAduit}>
        <Icon type="check" theme="outlined" />ᠬᠢᠨᠠᠯᠲᠠ ᠳ᠋ᠤ᠌ ᠲᠤᠰᠢᠶᠠᠬᠤ
                </Button>

    //审核通过
    const changestatus2 = () =>
      <Button type="defualt" disabled={selectedRowKeys.length > 0 ? false : true} onClick={this.auditVideoFun}>
        <Icon type="check" theme="outlined" />ᠬᠢᠨᠠᠨ ᠵᠥᠪᠰᠢᠶᠡᠷᠡᠪᠡ
            </Button>

    //审核退回
    const changestatus3 = () =>
      <Button type="defualt" disabled={selectedRowKeys.length > 0 ? false : true} onClick={this.auditVideoBack}>
        <Icon type="close" theme="outlined" />ᠬᠢᠨᠠᠨ ᠵᠥᠪᠰᠢᠶᠡᠷᠡᠭᠰᠡᠨ ᠦᠭᠡᠢ
            </Button>

    //上架
    const changestate = () =>
      <Button type="defualt" disabled={selectedRowKeys.length > 0 ? false : true} onClick={this.upVideo}>
        <Icon type="arrow-up" theme="outlined" />ᠨᠡᠢᠲᠡᠯᠡᠬᠦ
        </Button>

    //下架
    const changestate2 = () =>
      <Button type="defualt" disabled={selectedRowKeys.length > 0 ? false : true} onClick={this.upVideos}>
        <Icon type="arrow-down" theme="outlined" />ᠪᠠᠭᠤᠯᠭᠠᠬᠤ
        </Button>


    //推送
    const addpush = () =>
      <Button type="defualt" disabled={selectedRowKeys.length > 0 ? false : true} onClick={()=>this.showModal4(selectedRowKeys)}>
        <Icon type="sound" />app ᠳ᠋ᠤ᠌ ᠨᠡᠢᠲᠡᠯᠡᠬᠦ
                </Button>

    let addpushweixin;

    if (this.state.config_json.weixinPushSwitch) {
      //推送
      addpushweixin = () =>
        <Button type="defualt" disabled={selectedRowKeys.length > 0 ? false : true} onClick={this.showModal6}>
          <Icon type="sound" /> ᠸᠢᠴᠠᠲ ᠳᠤ᠌ ᠨᠡᠢᠲᠡᠯᠡᠬᠦ
          </Button>
    }


    //复制
    const copybtn = () =>
      <Button type="defualt" disabled={selectedRowKeys.length > 0 && !this.state.isNewAdd ? false : true} onClick={this.showModal3}>
        <Icon type="copy" />ᠳᠠᠷᠤᠮᠯᠠᠬᠤ
        </Button>

    const changeModuleTag = (data) => {
      switch (data) {
        case 'fcvideo':
          return '视频'
          break;
        case 'fcfind':
          return '发现';
          break;
        case 'fcinformation':
          return '资讯';
          break;
        case 'fcinformation_theme':
          return '专题';
          break;
      }
    }
    //列表
    const columns = [{
      title: '标题',
      dataIndex: 'title',
      key: 'title',

      render: (text, record, index) => {
        return (
          <div className="d_flex">
            <div className="h_table_div" key={index}>
              {record.module_name ? <Tag color="blue" >引用</Tag> : ''}
              {record.type ? <Tag color="green" >{record.type === 1 ? '文章' : record.type === 2 ? '图集' : 'banner'}</Tag> :
                record.module_name ? <Tag color="green" >{changeModuleTag(record.module_name)}</Tag> : ''}
              {record.top === 1 ? <Tag color="red" >置顶</Tag> : ''}
            </div>
            <div className='mon_text'>{record.title}</div>
          </div>
        )
      }
    }, {
      title: '创建人',
      dataIndex: 'create_user',
      key: 'create_user',
      width: 80,
    }, {
      title: '创建时间',
      dataIndex: 'create_time',
      key: 'create_time',
      width: 200,
    }, {
      title: '分类',
      dataIndex: 'class_name',
      key: 'class_name',

    }, {
      title: '审核状态',
      dataIndex: 'status',
      key: 'status',
      width: 90,
      render: (status) => {
        if (status === 0) {
          return <span style={{ color: '#f44336' }}>草稿</span>
        }
        if (status === 1) {
          return <span style={{ color: '#607d8b' }}>待审</span>
        }
        if (status === 2) {
          return <span style={{ color: '#4caf50' }}>审核通过</span>
        }
        if (status === 3) {
          return <span style={{ color: '#673ab7' }}>审核退回</span>
        }

      }
    }, {
      title: '上架情况',
      dataIndex: 'state',
      key: 'state',
      width: 90,
      render: (state) => {
        if (state == 1) {
          return <span style={{ color: '#4caf50' }}>已上架</span>
        }
        if (state == 0) {
          return <span style={{ color: '#afafaf' }}>已下架</span>
        }
      }
    }, {
      className: '',
      title: '所属版面',
      dataIndex: 'plate_name',
      key: 'plate_name',
      render: (text, record, index) => {
        if (text instanceof Array) {
          return text.map((item, key) => {
            let obj = {
              plate_id: record.plate_id[key],
              information_id: record.information_id
            }
            return [<a className='mon_text' onClick={() => { this.clickToPlate(obj) }}>{item}</a>, <Divider type="vertical" />]
          })

        } else {
          return <a className='mon_text' onClick={() => { this.clickToPlate(record) }}>{record.plate_name}</a>
        }
      }
    },
    ]
    const changeTag = (data) => {
      switch (data) {
        case '0':
          return '草稿'
          break;
        case '1':
          return '待审';
          break;
        case '2':
          return '审核通过';
          break;
        case '3':
          return '审核退回';
          break;
      }
    }
    const { selectedRowKeys2 } = this.state;
    const rowSelection = {
      selectedRowKeys: selectedRowKeys2,
      onChange: this.onSelectChange,
      hideDefaultSelections: true,
      onSelection: this.onSelection,
    };
    const treeData = [
      {
        title: '全部',
        value: 'all',
        key: 'all',
        children: [
          {
            title: '原文',
            value: 'a_all',
            key: 'a_all',
            children: [
              {
                title: '文章',
                value: 'a_1',
                key: 'a_1',
              },
              {
                title: '图集',
                value: 'a_2',
                key: 'a_2',
              },
              {
                title: 'banner',
                value: 'a_3',
                key: 'a_3',
              },
            ],
          },
          {
            title: '引用',
            value: 'q_all',
            key: 'q_all',
            children: [
              {
                title: '专题',
                value: 'q_theme',
                key: 'q_theme',
              },
              {
                title: '视频',
                value: 'q_video',
                key: 'q_video',
              }
            ],
          },
        ]
      },
    ]

    return (
      <div className='btn_group mon_btn_group'>
        {globalSearch()}
        {this.state.isAggregation?'':this.state.config_json && this.state.config_json.is_mengwen && addmongolianinfo()}
        {/* {this.state.config_json && this.state.config_json.is_mengwen ?
        <Button
          type="defualt"
          onClick={this.showMWList}
        >
          查看蒙文标题
        </Button>: null} */}
        {this.state.isAggregation?'':Authentication(addinformation, 'information/addinformation', loginModal)}
        {this.state.isAggregation?'':Authentication(usedmodule, 'information/usedmodule', loginModal)}
        {this.state.isAggregation?'':Authentication(copybtn, 'information/copy', loginModal)}
        {this.state.isAggregation?'':Authentication(deleteinformation, 'information/deleteinformation', loginModal)}
        {this.state.isAggregation?'':editplate()}
        {/* {Authentication(moveinformation, 'information/moveinformation', loginModal)} */}
        {Authentication(changestatus1, 'information/changestatus1', loginModal)}
        {Authentication(changestatus2, 'information/changestatus2', loginModal)}
        {Authentication(changestatus3, 'information/changestatus3', loginModal)}
        {Authentication(changestate, 'information/changestate', loginModal)}
        {Authentication(changestate2, 'information/changestate', loginModal)}

        {/* <Button type="defualt" disabled={selectedRowKeys.length > 0 ? false : true} onClick={this.edit}>
                    <Icon type="scissor" theme="outlined" />编辑
                </Button> */}


        {this.state.isAggregation?'':Authentication(addpush, 'push/addpush', loginModal)}

        {this.state.config_json.weixinPushSwitch && Authentication(addpushweixin, 'push/addpush', loginModal)}
        <Modal
          title="推送到"
          visible={this.state.visible6}
          onOk={this.handleOk6}
          onCancel={this.handleCancel6}
        >

          <Checkbox.Group onChange={this.checkboxChange} value={this.state.mp_checkbox}>
            <Row>
              {
                this.state.mplist.map((item) => {
                  return (
                    <Col key={item.id} style={{ marginBottom: '15px' }} ><Checkbox value={item.id}>{item.name}</Checkbox></Col>
                  )
                })
              }
            </Row>
          </Checkbox.Group>
        </Modal>

        <Modal
          title="移动到"
          visible={this.state.visible2}
          onOk={this.handleOk}
          onCancel={this.handleCancel}
        >
          <TreeSelect
            style={{ width: 300 }}
            value={this.state.key}
            dropdownStyle={{ maxHeight: 400 }}
            dropdownMatchSelectWidth
            treeData={treeList}
            placeholder="选择分类"
            treeDefaultExpandAll
            onChange={this.moveSelect}
          />
        </Modal>
        <Modal
          title="修改版面"
          visible={this.state.visibleEditPlate}
          onOk={this.handleEditPlateOk}
          onCancel={this.handleEditPlateCancel}
        >
          <div style={{ textAlign: "center" }}>
            <div style={{ textAlign: "left", paddingBottom: 10 }}>批量修改选中资讯的版面：</div>
            <TreeSelect

              style={{ width: 300 }}
              value={this.state.editPlateIds}
              dropdownStyle={{ maxHeight: 400 }}
              dropdownMatchSelectWidth
              placeholder="请选择资讯版面"
              treeData={this.props.video.treeList}
              multiple
              treeDefaultExpandAll
              onChange={this.handleChangePlate}
              multiple
            />
          </div>
        </Modal>
        <Modal
          title="复制"
          visible={this.state.visible3}
          onCancel={this.handleCancel3}
          onOk={this.handleOk3}
          width='648px'
        >
          <div style={{ height: '70px', textAlign: 'center' }}>
            复制到：<TreeSelect
              style={{ width: 300 }}
              dropdownStyle={{ maxHeight: 400, }}
              dropdownMatchSelectWidth
              treeData={this.props.video.treeList}
              placeholder="请选择版面"
              treeDefaultExpandAll
              onChange={(value) => this.setState({ copy: value })}
            />
          </div>
        </Modal>
        <Modal
          title="推送消息"
          visible={this.state.visible4}
          onCancel={this.handleCancel4}
          onOk={this.handleOk4}
          width='648px'
        >
         {
              this.props.video.selectedRowKeys.length==1&&<div style={{display:'flex',alignItems: 'center'}}><span style={{width:'50px'}}>标题：</span><Input  onInput={(e) => this.setState({pushMsgTitle:e.target.value})} value={this.state.pushMsgTitle} /></div>
            }
          <div style={{ height: '40px', lineHeight: '40px' }}>
           
            <RadioGroup onChange={(e) => this.setState({ pushMsg: e.target.value, pushDate: '' })} value={this.state.pushMsg}>
              <Radio value={1}>即时推送</Radio>
              <Radio value={2}>定时推送</Radio>
            </RadioGroup>
            {
              this.state.pushMsg === 2 ? <DatePicker style={{ width: '220px' }} showTime format="YYYY-MM-DD HH:mm:ss"
                onChange={(date, dateString) => this.setState({ pushDate: dateString })} /> : ''
            }
          </div>
          <p><b>注：已上架资讯才能推送</b></p>
        </Modal>
        <Modal
          title="全局搜索"
          className="vbModal"
          visible={this.state.visible5}
          onCancel={this.handleCancel5}
          onOk={this.handleOk5}
          width='1500px'
          footer={null}
        >
          <div >
            <Row gutter={24}>
              <Col span={6} >
                <div >
                  {this.state.quanxian.includes('information/changestate') ? 
                    <>
                    <Button className='mon_btn' type="defualt" disabled={selectedRowKeys2.length > 0 ? false : true} onClick={this.upVideo2}>
                      <Icon type="arrow-up" theme="outlined" />ᠨᠡᠢᠲᠡᠯᠡᠬᠦ
                    </Button>
                    <Button className='mon_btn' type="defualt" disabled={selectedRowKeys2.length > 0 ? false : true} onClick={this.upVideos2} style={{ marginLeft: 20 }}>
                      <Icon type="arrow-down" theme="outlined" />ᠪᠠᠭᠤᠯᠭᠠᠬᠤ
                    </Button>
                    </>
                        : ''
                      }
                      {this.state.quanxian.includes('information/deleteinformation')?
                      <Button className='mon_btn' type="defualt" disabled={selectedRowKeys2.length > 0 ? false : true} onClick={this.deleteAll2} style={{ marginLeft: 20 }}>
                        <Icon type="delete" theme="outlined" /> ᠪᠠᠯᠠᠯᠬᠤ
                      </Button>
                      : ''
                    }
                </div>
              </Col>

              <Col span={18} >
                <Form
                  className="ant-advanced-search-form mon_form"
                  onSubmit={this.handleSearch}
                  layout="inline"
                >
                  <Row gutter={24} >
                    <Col span={2} >
                      <Item label='ᠴᠠᠭ : '>
                        <RangePicker 
                          className="RangePicker" 
                          placeholder={['ᠡᠬᠢᠯᠡᠬᠦ ᠴᠠᠭ', 'ᠲᠡᠭᠦᠰᠬᠦ ᠴᠠᠭ']}
                          onChange={this.getRangePicker} 
                          value={this.state.valueRangePicker}
                        />
                      </Item>
                    </Col>
                    <Col span={2} >
                      {/*<Item label='ID'>*/}
                      {/*  <Input style={{ width: "80px" }} onChange={(e) => this.setState({ information_id: e.target.value })}*/}
                      {/*         value={this.state.information_id} />*/}
                      {/*</Item>*/}
                      <Item label='ᠵᠠᠩᠭᠢᠯᠠᠭ᠎ᠠ᠎ᠶᠢᠨ ᠦᠭᠡ᠎ᠪᠡᠷ ᠬᠠᠢᠬᠤ : '>
                        <Input style={{ width: "130px" }} onChange={(e) => this.setState({ keywords: e.target.value })}
                              value={this.state.keywords} />
                      </Item>
                    </Col>
                    <Col span={2} >
                      <Item label='ᠬᠢᠨᠠᠭᠰᠠᠨ ᠪᠠᠢᠳᠠᠯ : '>
                        <Select onChange={this.handleChange2} style={{ width: '100px' }} value={this.state.status}>
                          <Option value={null}>ᠪᠦᠭᠦ</Option>
                          <Option value="0">ᠡᠬᠡ ᠨᠣᠣᠷᠠᠭ</Option>
                          <Option value="1">ᠬᠢᠨᠠᠬᠤ ᠪᠡᠷ ᠪᠠᠢᠭ᠎ᠠ</Option>
                          <Option value="2">ᠬᠢᠨᠠᠨ ᠵᠥᠪᠰᠢᠶᠡᠷᠡᠪᠡ</Option>
                          <Option value="3">ᠬᠢᠨᠠᠨ ᠵᠥᠪᠰᠢᠶᠡᠷᠡᠭᠰᠡᠨ ᠦᠭᠡᠢ</Option>
                        </Select>
                      </Item>
                    </Col>
                    <Col span={2} >
                      <Item label='ᠨᠡᠢᠲᠡᠯᠡᠭᠰᠡᠨ ᠪᠠᠢᠳᠠᠯ : '>
                        <Select onChange={this.handleChange} style={{ width: '90px' }} value={this.state.state}>
                          <Option value={null}>ᠪᠦᠭᠦ</Option>
                          <Option value="0">ᠪᠠᠭᠤᠯᠭᠠᠪᠠ</Option>
                          <Option value="1">ᠨᠡᠢᠲᠡᠯᠡᠪᠡ</Option>
                        </Select>
                      </Item>
                    </Col>
                    <Col span={2} >
                      <Item label='ᠠᠩᠭᠢᠯᠠᠯ : '>
                        <Select onChange={(value) => {
                          this.setState({ class_id: value })
                        }} style={{ width: '90px' }} value={this.state.class_id}>
                          <Option value={null}>ᠪᠦᠭᠦ</Option>
                          {
                            this.props.video.classList.map((item, index) => {
                              return <Option key={index} value={item.class_id}>{item.class_name}</Option>
                            })
                          }
                        </Select>
                      </Item>
                    </Col>
                    <Col span={2} >
                      <Item label='ᠲᠥᠷᠦᠯ ᠵᠦᠢᠯ : '>
                        <TreeSelect
                          treeData={treeData}
                          value={this.state.cat}
                          onChange={(value) => {
                            this.setState({ cat: value });
                          }}
                          treeCheckable
                          showCheckedStrategy={SHOW_PARENT}
                          searchPlaceholder=""
                          style={{ width: '150px' }}
                        />
                      </Item>
                    </Col>
                    <Col span={2} style={{ display: 'flex' }}>
                      <Button className='mon_btn' type="primary" htmlType="submit" onClick={(e) => { this.searchTable() }}>ᠬᠠᠢᠬᠤ</Button>
                      <Button className='mon_btn' style={{ marginLeft: 8 }} onClick={this.resetSearch}>ᠳᠠᠬᠢᠵᠦ ᠲᠣᠬᠢᠷᠠᠭᠤᠯᠬᠤ</Button>
                    </Col>
                  </Row>
                </Form>
              </Col>
            </Row>
            
          </div>
          
          <Table
            className="table-search mon_table"
            columns={columns}
            dataSource={this.props.video.videoList.list}
            rowSelection={rowSelection}
            pagination={{
              current: this.props.video.videoList.pagination.page,
              onChange: (page, pageSize) => {
                this.searchTable(page);
              },
              total: this.props.video.videoList.pagination.total, //数据总数量
              size: 'small',
              showQuickJumper: true,
              pageSize: this.props.video.videoList.pagination.pageSize,  //显示几条一页

              style: { marginRight: '50px' },
            }}
          />
        </Modal>
      </div>
    )
  }
}
